import javax.swing.tree.TreeNode;

import javafx.scene.media.Track;

/*
 * @lc app=leetcode.cn id=101 lang=java
 *
 * [101] 对称二叉树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isSymmetric(TreeNode root) {
       return plus(root.left,root.right);
    }
    boolean plus(TreeNode q,TreeNode p){
        if (q==null) {
            return p==null;
        }
        if (p==null) {
            return q==null;
            
        }
        if (q.val!=p.val) {
            return false;
            
        }
        return plus(q.left, p.right)&&plus(q.right, p.left);
    }
}
// @lc code=end

